﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using Fulcrum.ControlGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.ControlGenerator
{
    [TestClass]
    public class RoutedCommandBindingDataContextTests
    {
        [TestMethod]
        public void TestCanExecuteAlways()
        {
            var config = CreateConfig();

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual(false, routedCommandBinding.CanExecuteAlways);
        }

        private static RoutedCommandBindingDataContext CreateRoutedCommandBinding(MockRoutedCommandBindingConfiguration config)
        {
            var routedCommandBinding = new RoutedCommandBindingDataContext(config);
            return routedCommandBinding;
        }

        [TestMethod]
        public void TestCanExecuteMethodName()
        {
            var config = CreateConfig();

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual("OnFooBarCanExecute", routedCommandBinding.CanExecuteMethodName);
        }

        [TestMethod]
        public void TestCommandName()
        {
            var config = CreateConfig();

            var routedCommandBinding = new RoutedCommandBindingDataContext(config, "MyType");

            Assert.AreEqual("FooBarCommand", routedCommandBinding.CommandName);
        }

        [TestMethod]
        public void TestCommandName_NoGeneration()
        {
            var config = CreateConfig();

            var routedCommandBinding = new RoutedCommandBindingDataContext(config);

            Assert.AreEqual("FooBar", routedCommandBinding.CommandName);
        }

        [TestMethod]
        public void TestExecutedMethodName()
        {
            var config = CreateConfig();

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual("OnFooBarExecuted", routedCommandBinding.ExecutedMethodName);
        }

        [TestMethod]
        public void TestName()
        {
            var config = CreateConfig();

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual("FooBar", routedCommandBinding.Name);
        }

        [TestMethod]
        public void TestOwningType()
        {
            var config = CreateConfig();

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual("AType", routedCommandBinding.OwningType);
        }

        [TestMethod]
        public void TestStaticCanExecuteMethodName_NotOwned()
        {
            var config = CreateConfig();

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual("FooBar_CommandCanExecute", routedCommandBinding.StaticCanExecuteMethodName);
        }

        [TestMethod]
        public void TestStaticCanExecuteMethodName_Owned()
        {
            var config = CreateConfig();

            var routedCommandBinding = new RoutedCommandBindingDataContext(config, "MyType");

            Assert.AreEqual("FooBarCommand_CommandCanExecute", routedCommandBinding.StaticCanExecuteMethodName);
        }

        [TestMethod]
        public void TestStaticExecutedMethodName_NotOwned()
        {
            var config = CreateConfig();

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual("FooBar_CommandExecuted", routedCommandBinding.StaticExecutedMethodName);
        }

        [TestMethod]
        public void TestStaticExecutedMethodName_Owned()
        {
            var config = CreateConfig();

            var routedCommandBinding = new RoutedCommandBindingDataContext(config, "MyType");

            Assert.AreEqual("FooBarCommand_CommandExecuted", routedCommandBinding.StaticExecutedMethodName);
        }

        [TestMethod]
        public void TestSummary()
        {
            var config = CreateConfig();
            config.Summary = "my summary";

            var routedCommandBinding = CreateRoutedCommandBinding(config);

            Assert.AreEqual("my summary", routedCommandBinding.Summary);
        }

        private static MockRoutedCommandBindingConfiguration CreateConfig()
        {
            var config = new MockRoutedCommandBindingConfiguration();
            config.Name = "FooBar";
            config.OwningType = "AType";

            return config;
        }
    }
}
